<template>
  <ul class='member-center first-box'>
    <li v-for="(item,index) in getListData" v-if="!item.isLine" :class="{'canClick':item.canClick}" @click="getMoreInfo(item)">
      <p>
        <img class="logo fl" :src="item.img" alt="">
        <span class="fl">{{item.label}}</span>
        <span class="value fl"><img class="level-logo fl" v-show="item.logo" :src="item.logoImg" alt=""> {{item.value}}</span>
        <span class="fr" v-show="item.canClick"><img :src="imgs.go" alt=""></span>
        <span v-if="item.btn" class="fr btn" @click.stop="item.btn.click"><a v-if="item.btn.phone" :href="item.btn.phone?'tel:'+item.value:item.btn.url">{{item.btn.label}}</a><span v-else>{{item.btn.label}}</span></span>
        <span v-if="item.radio" class="fr"><img :src="item.active?imgs.choose1:imgs.choose" alt=""></span>
      </p>
    </li>
    <li class="grey-line" v-else></li>
  </ul>
</template>
<script>

export default {
  props:["data"],
  components: {},
  name: "",
  data() {
    return {
      imgs:{
        go:require('../../../assets/img/vip/center/8.png'),
        choose:require('../../../assets/img/hpmepage/renew/choose.png'),
        choose1:require('../../../assets/img/hpmepage/renew/choose_1.png'),
      },
      listData:[
        {
          img:require('../../../assets/img/vip/center/1.png'),
          label:"会员卡：",
          value:"12345678912",
          key:"",
        },{
          img:require('../../../assets/img/vip/center/2.png'),
          label:"会员等级：",
          value:"黄金会员",
          logo:true,
          logoImg:require('../../../assets/img/vip/vip1.png'),
          key:"",
        },{
          img:require('../../../assets/img/vip/center/3.png'),
          label:"会员卡余额：",
          value:"0.00",
          key:"",
          btn:{
            label:"充值",
            url:"",
            click:this.recharge,
          }
        },{
          img:require('../../../assets/img/vip/center/4.png'),
          label:"我的积分：",
          value:"123452",
          key:"",
        },{
          isLine:true
        },{
          img:require('../../../assets/img/vip/center/5.png'),
          label:"消费明细",
          canClick:true,
          url:"/member/consume", //地址
        },{
          img:require('../../../assets/img/vip/center/6.png'),
          label:"积分明细",
          canClick:true,
          url:"/member/integral",
        },{
          img:require('../../../assets/img/vip/center/7.png'),
          label:"充值明细",
          canClick:true,
          url:"/member/recharge", 
        }
      ]
    };
  },

  computed:{
    getListData(){
      return this.data||this.listData
    }
  },
  methods: {
    recharge(){
      this.$router.push("/fullmoney")
    },

    // 查看详情
    getMoreInfo(item){
      if(item.canClick)this.$router.push(item.url)
      if(item.canClick&&!item.url){
        this.$store.state.dialogs.alert.content=item.label+" 正在升级中，请等待"
        this.$store.state.dialogs.alert.show=true
      }
      if(item.radio)this.changeChoose(item)
    },

    changeChoose(item){
      this.data.forEach(ele => {
          ele.active=false
      });
      this.$set(item,"active",true)
    },

    getList(){
      var params={
        // userId:sessionStorage.getItem("userId")
      }
      _g.apiPost("vipCenter/init.do",params).then(res=>{
        if(res.status){
          _g.toMessage(res)
          this.$router.go(-1)
        }
        this.listData[0].value=res.data.phone
        this.listData[1].value=res.data.name
        this.listData[2].value=res.data.money||0
        this.listData[3].value=res.data.integral||0
      })
    }
  },
  created() {
    var path = this.$router.history.current.fullPath
    console.log(path)
    if(path=="/member/center"){
      this.getList()
    }
  }
};
</script>
<style lang="scss" scoped>
.member-center {
  font-size: 14px;
  color: #333;

  li{
    height: 40px;
    padding: 0 15px;
    background-color: #fff;
    box-sizing: border-box;
    border-bottom: 1px solid #f2f2f2;

    p{
      padding: 10px 0;
      height: 20px;

      img{
        width: 17px;
        height: 17px;
        transform: translateY(1.5px);
        margin-right: 5px;
      }

      .value{
        color: #999;
        display: inline-block;
        min-width: 120px;
        line-height: 20px;
      }
      .level-logo{
        width: 17px;
        height: 17px;
        transform: translateY(0px);
      }

      .btn{
        color: #F39519;
        height: 20px;
        width: 50px;
        text-align: center;
        border-radius: 20px;
        font-size: 12px;
        line-height: 18px;
        border: 1px solid #F39519;
        box-sizing: border-box;
        padding: 0;

        a{
          color: #F39519;
        }
      }
      .btn:active{
        opacity: .6;
      }
      
    }
  }
  li:nth-child(2) p .value{
    font-size: 12px;
    color: #FC9522;
  }

  .grey-line{
    height: 5px;
    background-color: #f2f2f2;
  }
  .canClick:active{
    opacity: .6;
  }
}
</style>